package com.atguigu.edu2021.mock.stage;

import com.atguigu.edu2021.mock.config.AppConfig;
import com.atguigu.edu2021.mock.factory.UserSession;
import com.atguigu.edu2021.mock.log.AppCommon;
import com.atguigu.edu2021.mock.log.AppDisplay;
import com.atguigu.edu2021.mock.log.AppMain;
import com.atguigu.edu2021.mock.log.AppPage;
import com.atguigu.edu2021.mock.log.enums.ItemType;
import com.atguigu.edu2021.mock.log.enums.PageId;
import com.atguigu.mock.util.LogUtil;
import com.atguigu.mock.util.RandomBox;
import com.atguigu.mock.util.RandomNum;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("courseList")
public class CourseListStage implements Stage {
    @Override
    public boolean handle() {
        AppMain mainlog = mainlog();
        LogUtil.logToJson(mainlog);
        UserSession.setLastPageId(PageId.course_list);


        return true;
    }

    private   AppMain      mainlog(){

        AppCommon appCommon = UserSession.getAppCommon();

        String  item=  new RandomBox(AppConfig.searchKeywords).getRandStringValue();
        Integer durTime= RandomNum.getRandInt(5000,AppConfig.page_during_max_ms);
        AppPage appPage = AppPage.builder()
                .last_page_id(UserSession.getLastPageId())
                .item_type(ItemType.keyword)
                .item(item)
                .during_time(durTime)
                .page_id(PageId.course_list).build();


        List<AppDisplay> appDisplayList = AppDisplay.builder().buildList();
        UserSession.addTimeByDuringTime(durTime);
        AppMain appMain = AppMain.builder().common(appCommon).page(appPage).displays(appDisplayList).ts(UserSession.getCurDateTime().getTime()).checkError().build();
        return  appMain;

    }
}
